﻿using System;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x02000391 RID: 913
public class AnimationView : MonoBehaviour
{
	// Token: 0x060017DD RID: 6109 RVA: 0x00097510 File Offset: 0x00095710
	private void Start()
	{
		this.control = Camera.main.GetComponent<InterfaceControl>();
		Button[] componentsInChildren = base.GetComponentsInChildren<Button>();
		componentsInChildren[0].onClick.AddListener(delegate()
		{
			this.OnPrevious();
		});
		componentsInChildren[1].onClick.AddListener(delegate()
		{
			this.OnNext();
		});
		this.speedSlider = base.GetComponentInChildren<Slider>();
		this.speedSlider.minValue = 0f;
		this.speedSlider.maxValue = 3f;
		this.speedSlider.value = 1f;
		this.speedSlider.onValueChanged.AddListener(delegate(float speed)
		{
			this.control.ChangeAnimationSpeed(speed);
		});
		this.placeholder = (Resources.Load("UI/Button/ListElement") as GameObject);
		this.grid = base.GetComponentInChildren<GridLayoutGroup>();
		RectTransform component = this.grid.GetComponent<RectTransform>();
		int num = (int)component.rect.height / 30;
		this.elementsCount = num;
		this.pageCount = this.control.animations.Length / this.elementsCount + 1;
		this.elements = new Text[this.elementsCount];
		for (int i = 0; i < this.elementsCount; i++)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.placeholder, this.grid.transform);
			gameObject.name = "Element " + i;
			this.elements[i] = gameObject.GetComponent<Text>();
			Button component2 = gameObject.GetComponent<Button>();
			int number = i;
			component2.onClick.AddListener(delegate()
			{
				this.OnElementClick(number);
			});
		}
		this.LoadPage(this.page);
		this.control.OnSelected += this.OnChangedCharacter;
		base.gameObject.SetActive(false);
	}

	// Token: 0x060017DE RID: 6110 RVA: 0x000976F6 File Offset: 0x000958F6
	private void OnChangedCharacter()
	{
		if (base.gameObject.activeSelf)
		{
			this.ReloadValues();
		}
	}

	// Token: 0x060017DF RID: 6111 RVA: 0x0009770E File Offset: 0x0009590E
	private void OnEnable()
	{
		this.ReloadValues();
	}

	// Token: 0x060017E0 RID: 6112 RVA: 0x00097718 File Offset: 0x00095918
	private void ReloadValues()
	{
		if (this.control == null)
		{
			return;
		}
		if (this.control.humanoid == null)
		{
			base.gameObject.SetActive(false);
			return;
		}
		this.speedSlider.value = this.control.GetAnimationSpeed();
	}

	// Token: 0x060017E1 RID: 6113 RVA: 0x00097770 File Offset: 0x00095970
	private void OnElementClick(int i)
	{
		this.control.SetAnimation(this.elements[i].text);
	}

	// Token: 0x060017E2 RID: 6114 RVA: 0x0009778C File Offset: 0x0009598C
	private void LoadPage(int pag)
	{
		int num = pag * this.elementsCount;
		for (int i = 0; i < this.elementsCount; i++)
		{
			int num2 = num + i;
			if (num2 < this.control.animations.Length)
			{
				this.elements[i].text = this.control.animations[num2];
				this.elements[i].gameObject.SetActive(true);
			}
			else
			{
				this.elements[i].gameObject.SetActive(false);
			}
		}
	}

	// Token: 0x060017E3 RID: 6115 RVA: 0x00097815 File Offset: 0x00095A15
	private void OnNext()
	{
		this.page++;
		if (this.page >= this.pageCount)
		{
			this.page = 0;
		}
		this.LoadPage(this.page);
	}

	// Token: 0x060017E4 RID: 6116 RVA: 0x00097849 File Offset: 0x00095A49
	private void OnPrevious()
	{
		this.page--;
		if (this.page < 0)
		{
			this.page = this.pageCount - 1;
		}
		this.LoadPage(this.page);
	}

	// Token: 0x04001A16 RID: 6678
	private Slider speedSlider;

	// Token: 0x04001A17 RID: 6679
	private GameObject placeholder;

	// Token: 0x04001A18 RID: 6680
	private int elementsCount;

	// Token: 0x04001A19 RID: 6681
	private GridLayoutGroup grid;

	// Token: 0x04001A1A RID: 6682
	private InterfaceControl control;

	// Token: 0x04001A1B RID: 6683
	private int page;

	// Token: 0x04001A1C RID: 6684
	private int pageCount;

	// Token: 0x04001A1D RID: 6685
	private Text[] elements;
}
